package com.donger.upms.biz.controller;


import cn.hutool.core.util.StrUtil;
import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.metadata.IPage;
import com.baomidou.mybatisplus.extension.plugins.pagination.Page;
import com.donger.common.core.utils.Res;
import com.donger.common.core.utils.Result;
import com.donger.upms.api.entity.SysLog;
import com.donger.upms.api.service.ISysLogService;
import lombok.AllArgsConstructor;
import org.springframework.web.bind.annotation.*;

/**
 * <p>
 * 系统日志 前端控制器
 * </p>
 *
 * @author xyx
 * @since 2019-01-12
 */
@AllArgsConstructor
@RestController
@RequestMapping("/sys/log")
public class SysLogController extends BaseController {

    private static final String MODULE_NAME = "系统日志管理";

    private final ISysLogService sysLogService;


    /**
     * 列表
     */
    @ResponseBody
    @GetMapping("/list")
    public Result<IPage> list(Page<SysLog> page, SysLog sysLog) {
        return Res.ok(sysLogService.page(page, new LambdaQueryWrapper<SysLog>()
                .like(StrUtil.isNotEmpty(sysLog.getModuleName()), SysLog::getModuleName, sysLog.getModuleName())
                .eq(StrUtil.isNotEmpty(sysLog.getLogType()), SysLog::getLogType, sysLog.getLogType())
        ));
    }

    @GetMapping("/info/{id}")
    public Result info(@PathVariable Long id) {
        return Res.ok(sysLogService.getById(id));
    }

    @DeleteMapping("/delete/{id}")
    public Result delete(@PathVariable Long id) {
        return Res.ok(sysLogService.removeById(id));
    }
}

